package com.cscec5b.inspection.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebCorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                // 前端开发端口：把两种都加上，避免 127.0.0.1 与 localhost 不一致
                .allowedOrigins("http://localhost:5173", "http://127.0.0.1:5173")
//                .allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")
                .allowedMethods("*")
                .allowedHeaders("Content-Type","X-Auth-Token","Authorization")
                .exposedHeaders("X-Auth-Token")
                .allowCredentials(true)   // 如果要用 Session/Cookie 必须 true
                .maxAge(3600);
    }
}
